/* GUI CONVERTED from soiv1001.p (converter v1.76) Sun May 25 18:34:46 2003 */
/* soiv1001.p - INVOICE HISTORY INVOICE REPRINT MAINLOOP                     */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.40 $                                                         */
/*V8:ConvertMode=Report                                                      */
/* REVISION: 8.5      CREATED: 10/20/97          BY: *H1F8* Nirav Parikh     */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E     LAST MODIFIED: 04/28/98   BY: *L00L* Adam Harris       */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* REVISION: 8.6E     LAST MODIFIED: 06/23/98   BY: *L024* Sami Kureishy     */
/* REVISION: 8.6E     LAST MODIFIED: 12/04/98   BY: *J360* Poonam Bahl       */
/* REVISION: 8.6E     LAST MODIFIED: 02/01/99   BY: *L0D5* Robin McCarthy    */
/* REVISION: 8.6E     LAST MODIFIED: 02/05/99   BY: *J38T* Poonam Bahl       */
/* REVISION: 8.6E     LAST MODIFIED: 05/07/99   BY: *J3DQ* Niranjan R.       */
/* REVISION: 8.6E     LAST MODIFIED: 10/05/99   BY: *L0JV* Anup Pereira      */
/* REVISION: 9.1      LAST MODIFIED: 03/06/00   BY: *N05Q* Luke Pokic        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 02/16/00   BY: *N06R* Denis Tatarik     */
/* REVISION: 9.1      LAST MODIFIED: 05/07/00   BY: *N09G* Luke Pokic        */
/* REVISION: 9.1      LAST MODIFIED: 06/27/99   BY: *N0DQ* Katie Hilbert     */
/* REVISION: 9.1      LAST MODIFIED: 07/03/00   BY: *N0DX* Mudit Mehta       */
/* REVISION: 9.1      LAST MODIFIED: 08/23/00   BY: *N0ND* Mark Brown        */
/* REVISION: 9.1      LAST MODIFIED: 11/07/00   BY: *L15K* Kaustubh K        */
/* REVISION: 9.1      LAST MODIFIED: 10/13/00   BY: *N0W8* Mudit Mehta        */
/* Revision: 1.30     BY: Katie Hilbert       DATE: 04/01/01   ECO: *P002*    */
/* Revision: 1.31     BY: Manisha Sawant      DATE: 05/08/01   ECO: *N0YD*    */
/* Revision: 1.32     BY: Ellen Borden        DATE: 07/09/01   ECO: *P007*    */
/* Revision: 1.33     BY: Hareesh V.          DATE: 08/20/01   ECO: *N11L*    */
/* Revision: 1.34     BY: Vinod Nair          DATE: 08/24/01   ECO: *N11P*    */
/* Revision: 1.35     BY: Tiziana Giustozzi   DATE: 10/02/01   ECO: *N138*    */
/* Revision: 1.37     BY: Mercy Chittilapilly DATE: 10/08/02   ECO: *N1W1*    */
/* Revision: 1.38     BY: Amit Chaturvedi     DATE: 01/20/03   ECO: *N20Y*    */
/* Revision: 1.39     BY: Vandna Rohira       DATE: 04/28/03   ECO: *N1YL*    */
/* $Revision: 1.40 $    BY: Narathip W.         DATE: 05/21/03   ECO: *P0S8*    */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* THIS PROGRAM IS SIMILAR TO sorp1001.p. CHANGES DONE IN THIS PROGRAM       */
/* MAY ALSO NEED TO BE DONE IN sorp1001.p.                                   */

/*! N1YL HAS CHANGED THE WAY TAXABLE/NON-TAXABLE AMOUNT IS CALCULATED.
    THE ORDER DISCOUNT IS APPLIED FOR EACH LINE TOTAL AND THEN IT IS
    SUMMED UP TO CALCULATE THE TAXABLE/NON-TAXABLE AMOUNT BASED ON THE
    TAXABLE STATUS OF EACH LINE. PREVIOUSLY, TAXABLE/NON-TAXABLE AMOUNT
    WAS OBTAINED FROM THE GTM TABLES. THIS CAUSED PROBLEMS WHEN
    MULTIPLE TAXABLE BASES ARE USED TO CALCULATE TAX.

    TAXABLE/NON-TAXABLE AMOUNT WILL NOW BE DISPLAYED IN THE TRAILER
    FRAME BASED ON THE VALUE OF THE FLAG "DISPLAY TAXABLE/NON-TAXABLE
    AMOUNT ON TRAILER" IN THE GLOBAL TAX MANAGEMENT CTRL FILE
 */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdeclre.i}
{cxcustom.i "SOIV1001.P"}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE soiv1001_p_2 "Print Call Invoice Detail"
/* MaxLen: Comment: */

&SCOPED-DEFINE soiv1001_p_10 "Include Credit Memos"
/* MaxLen: Comment: */

&SCOPED-DEFINE soiv1001_p_11 "Print Features and Options"
/* MaxLen: Comment: */

&SCOPED-DEFINE soiv1001_p_12 "Include Invoices"
/* MaxLen: Comment: */

&SCOPED-DEFINE soiv1001_p_13 "Override Print Inv Hist"
/* MaxLen: Comment: */

&SCOPED-DEFINE soiv1001_p_14 "Print Lot/Serial Numbers Shipped"
/* MaxLen: Comment: */

&SCOPED-DEFINE soiv1001_p_30 "Total Prepaid"
/* MaxLen: 18 Comment: */

&SCOPED-DEFINE soiv1001_p_31 "Amount Due"
/* MaxLen: 14 Comment: */

/* ********** End Translatable Strings Definitions ********* */

{&SOIV1001-P-TAG1}
define     shared variable rndmthd          like rnd_rnd_mthd.
define     shared variable oldcurr          like ih_curr.
define new shared variable undo_txdetrp     like mfc_logical.
define new shared variable rmaso            like mfc_logical.
define            variable svremarks        as character format "x(58)"
   no-undo.
define     shared variable due_date         like idh_due_date.
define     shared variable due_date1        like idh_due_date.
define     shared variable inv              like idh_inv_nbr.
define     shared variable inv1             like idh_inv_nbr.
define     shared variable nbr              like ih_nbr.
define     shared variable nbr1             like ih_nbr.
define     shared variable site             like ih_site.
define     shared variable site1            like ih_site.
define     shared variable print_lotserials like mfc_logical initial no
   label {&soiv1001_p_14}.
define     shared variable first_line       like mfc_logical.
define     shared variable pages            as integer.
define     shared variable comp_addr        like soc_company.
define     shared variable msg              like msg_desc.
define     shared variable inv_date         like ih_inv_date.
define     shared variable inv_date1        like ih_inv_date.
define     shared variable ih_recno         as recid.
define     shared variable company          as character
   format "x(38)" extent 6.
define     shared variable billto           as character
   format "x(38)" extent 6.
define     shared variable soldto           as character
   format "x(38)" extent 6.
define     shared variable termsdesc        like ct_desc.
define     shared variable shipdate         like ih_ship_date.
define     shared variable shipdate1        like shipdate.
define     shared variable addr             as character
   format "x(38)" extent 6.
define     shared variable print_options    like mfc_logical initial no
   label {&soiv1001_p_11}.
define     shared variable base_rpt         as character.
define     shared variable override_print_hist like mfc_logical
   label {&soiv1001_p_13}.
define     shared variable hdr_po           as character format "X(38)".
define     shared variable cust             like ih_cust.
define     shared variable cust1            like ih_cust.
define     shared variable bill             like ih_bill.
define     shared variable bill1            like ih_bill.

{soivtot1.i}

/* DEFINE VARIABLES FOR INVOICE TOTALS. */
define     shared variable resale           like cm_resale.
define new shared frame phead1.
define     shared variable call-detail      like mfc_logical
   label {&soiv1001_p_2}.

/* DEFINE VARIABLES FOR DISPLAY OF VAT REG NO & COUNTRY CODE */
{gpvtegl.i}
{gpvtecdf.i &var="shared"}
{gpvtepdf.i &var="shared"}

define     shared variable incinv           like mfc_logical initial yes
   label {&soiv1001_p_12}.
define     shared variable incmemo          like mfc_logical initial yes
   label {&soiv1001_p_10}.
define            variable currdisp         like so_curr no-undo.
define new shared variable col-80           like mfc_logical
   initial true.
define buffer ih_buff for ih_hist.
define            variable oldsession       as character no-undo.
define            variable prepaid-lbl      as character format "x(12)"
   no-undo.
define            variable prepaid_fmt      as character no-undo.
define            variable prepaid_old      as character no-undo.
define            variable tot_prepaid_amt  like so_prepaid.
define new shared variable disc_prnt_label  as character format "x(8)".
define            variable hdl_sum_disc_lbl as handle no-undo.
define            variable tax_tr_type      like tx2d_tr_type
   initial "16" no-undo.
define new shared variable sacontract       like mfc_logical.
define            variable print_invoice    like mfc_logical no-undo.
define            variable hdr_call         as character
   format "x(21)" no-undo.
define            variable call-lbl         as character format "x(16)"
   no-undo.
define variable tot_prepaid_nett like so_prepaid
   label {&soiv1001_p_30} no-undo.
define variable tot_ptax_amt     like ih_prep_tax no-undo.
define variable amt_due_af_prep  like so_prepaid
   label {&soiv1001_p_31} no-undo.
define variable add-trl-length   as integer no-undo.
define variable et_tot_prepaid_nett like tot_prepaid_amt no-undo.
define variable et_tot_ptax_amt     like tot_prepaid_amt no-undo.
define variable et_tot_prepaid_amt  like tot_prepaid_amt no-undo.
define variable et_amt_due_af_prep  like tot_prepaid_amt no-undo.
define variable price_fmt           as character no-undo.
define variable vlResult like mfc_logical no-undo.
define variable vcCreditCardMsg as character format "x(80)"
   extent 3 no-undo.
define variable translation as character no-undo.
define variable c-cont as character format "x(35)" no-undo.
define variable l_skip_rec like mfc_logical        no-undo.
{&SOIV1001-P-TAG7}

define variable auth_price          like sod_price
   format "->>>>,>>>,>>9.99"                             no-undo.
define variable auth_found          like mfc_logical     no-undo.

define new shared temp-table t_absr_det                  no-undo
field t_absr_reference like absr_reference
field t_absr_qty       as decimal format "->>>>,>>>,>>9.99"
field t_absr_ext       as decimal format "->>>>,>>>,>>9.99".

{sodiscwk.i &new="new"}

assign
   prepaid-lbl = getTermLabel("AMOUNT_PAID",11) + ":"
   call-lbl = getTermLabel("CALL_NUMBER",14) + ": "
   c-cont =  CAPS(dynamic-function ('getTermLabelFillCentered' in h-label,
                                  input "CONTINUED",
                                  input 35,
                                  input '*')).

/* SHARED WORKFILE FOR SUMMARY DISCOUNTS */
{etvar.i}
{etrpvar.i &new="new"}
{etdcrvar.i "new"}

{mfivtrla.i  "NEW"}
{&SOIV1001-P-TAG38}
{wbgp03.i &new="NEW SHARED"}

{etihtfrm.i}

hdl_sum_disc_lbl = prnt_sum_disc_amt:handle in frame disc_sum_print.
/* ASSIGN ORIGINAL FORMAT TO _OLD VARIABLES */
assign
   nontax_old    = nontaxable_amt:format
   taxable_old   = taxable_amt:format
   line_tot_old  = line_total:format
   disc_old      = disc_amt:format
   trl_amt_old   = ih_trl1_amt:format
   tax_amt_old   = tax_amt:format
   container_old = container_charge_total:format
   line_charge_old = line_charge_total:format
   ord_amt_old   = ord_amt:format.

FORM /*GUI*/ 
   tot_prepaid_amt      colon 60
   tot_ptax_amt         colon 60
   tot_prepaid_nett     colon 60
   skip(1)
   amt_due_af_prep      colon 60
with STREAM-IO /*GUI*/  frame ihprepd width 80
   side-labels.

/* SET EXTERNAL LABELS */
setFrameLabels(frame ihprepd:handle).

/* PREPAID EURO FRAME */
FORM /*GUI*/ 
   tot_prepaid_amt      colon 60
   et_tot_prepaid_amt   at 80 no-attr-space no-label
   tot_ptax_amt         colon 60
   et_tot_ptax_amt      at 80 no-attr-space no-label
   tot_prepaid_nett     colon 60
   et_tot_prepaid_nett  at 80 no-attr-space no-label
   skip(1)
   amt_due_af_prep      colon 60
   et_amt_due_af_prep   at 80 no-attr-space no-label
with STREAM-IO /*GUI*/  frame ihprepdeuro side-labels width 132 attr-space.

/* SET EXTERNAL LABELS */
setFrameLabels(frame ihprepdeuro:handle).

assign prepaid_old = tot_prepaid_amt:format.

find first rmc_ctrl no-lock no-error.

oldsession = SESSION:numeric-format.

mainloop:

do:
   for each ih_buff where
         (override_print_hist or ih_inv_mthd = ""
         or ih_inv_mthd begins " "
         or ih_inv_mthd begins "b"
         or ih_inv_mthd begins "p")
         and (ih_inv_nbr >= inv and ih_inv_nbr <= inv1)
         and (ih_nbr >= nbr and ih_nbr <= nbr1)
         and (ih_ship_date >= shipdate and ih_ship_date <= shipdate1)
         and (ih_inv_date >= inv_date and ih_inv_date <= inv_date1)
         and (ih_cust >= cust and ih_cust <= cust1)
         and (ih_bill >= bill and ih_bill <= bill1)
         and (ih_site >= site and ih_site <= site1)
       AND LOOKUP(ih_site,GLOBAL_user_site) > 0 
         no-lock break by ih_inv_nbr:
      assign
         et_new_page        = true
         et_ext_price_total = 0
         l_skip_rec         = no.

      /* MOVED THE CODE FOR GETTING THE ROUNDING METHOD FROM BELOW */
      /* AS IT IS REQUIRED BY THE PROCEDURE p-get-ord-amt          */
      {gprunp.i "mcpl" "p" "mc-get-rnd-mthd"
         "(input  ih_curr,
           output rndmthd,
           output mc-error-number)"}

      if mc-error-number <> 0
      then do:
         {mfmsg.i mc-error-number 3}
         next.
      end. /* IF mc-error-number <> 0 */

      /* EXCLUDE CREDIT/DEBIT INVOICE */
      if not incinv
         or not incmemo
      then do:

         /* OBTAIN TOTAL INVOICE VALUE */
         if first-of(ih_buff.ih_inv_nbr)
         then
            run p-get-ord-amt(input  ih_buff.ih_inv_nbr,
                              output ord_amt).

         
/*GUI*/ {mfguirex.i  "false"} /*Replace mfrpexit*/


         /* SKIP THE DEBIT/CREDIT INVOICE */
         if (not incinv
             and ord_amt    >= 0)
            or (not incmemo
                and ord_amt  < 0)
         then
            l_skip_rec = yes.

      end. /* IF NOT incinv OR ... */

      if l_skip_rec
      then
         next.

      {&SOIV1001-P-TAG8}
      {soivhfrm.i }
      /* phead1 PAGE-TOP FRAME DEFINITION */
      view frame phead1.
      {&SOIV1001-P-TAG9}

      {&SOIV1001-P-TAG2}
      if first-of(ih_inv_nbr) then page.
      {&SOIV1001-P-TAG3}
      if ih_fsm_type = "FSM-RO" then tax_tr_type = '38'.
      pages = page-number - 1.

      if (oldcurr <> ih_curr) or (oldcurr = "") then do:

         /* DETERMINE CURRENCY DISPLAY AMERICAN OR EUROPEAN */
         find rnd_mstr where rnd_rnd_mthd = rndmthd no-lock no-error.

         if not available rnd_mstr then do:
            /* ROUND METHOD RECORD NOT FOUND */
            {pxmsg.i &MSGNUM=863 &ERRORLEVEL=3}
            next.
         end. /* IF AVAIL rnd_mstr */

         /* IF RND_DEC_PT = COMMA FOR DECIMAL POINT */
         /* THIS IS THE EUROPEAN CURRENCY FORMAT */

         if (rnd_dec_pt = ",")
         then SESSION:numeric-format = "European".
         else SESSION:numeric-format = "American".
         {socurfmt.i}
         /* SET CURRENCY DEPENDENT FORMATS */
         prepaid_fmt = prepaid_old.

         {gprun.i ""gpcurfmt.p"" "(input-output prepaid_fmt,
                                   input rndmthd)"}
         oldcurr = ih_curr.
      end.  /* IF (OLDCURR <> IH_CURR) */

      {&SOIV1001-P-TAG4}
      if first-of (ih_inv_nbr) then
      {&SOIV1001-P-TAG5}
      do for ih_hist:
         assign
            tot_prepaid_amt = 0
            tot_ptax_amt = 0.
         for each ih_hist where ih_hist.ih_inv_nbr = ih_buff.ih_inv_nbr
               no-lock break by ih_inv_nbr:
            first_line = yes.
            /* PRINT INVOICES, CREDITS, OR BOTH */

            if first-of(ih_inv_nbr) then do:
               /* INITIALIZE VARIABLES FOR INVOICE TOTALS.*/
               {soivtot2.i}
            end. /* IF FIRST-OF ih_inv_nbr */

            assign
               ih_recno = recid(ih_hist)
               base_rpt = ih_curr.

            assign
               rmaso = no
               sacontract = no.

            /* RMASO INDICATES AN RMA INVOICE */
            if ih_fsm_type = "RMA" then
               rmaso = yes.

            /* SACONTRACT INDICATES A SERVICE CONTRACT INVOICE */
            if ih_fsm_type = "SC" then
               sacontract = yes.
            /* IF "PRINT NO CHARGE RECEIPTS" (rmc_prt_rtn) IS NO, */
            /* AND THE RMA INVOICE HAS ONLY ZERO PRICED RECEIPT   */
            /* LINES, THEN WE DON'T PRINT THE INVOICE.            */

            if available rmc_ctrl and
               not rmc_prt_rtn and
               rmaso
            then do:
               print_invoice = no.
               for each idh_hist no-lock
                     where idh_inv_nbr = ih_inv_nbr
                     and idh_qty_inv <> 0:

                  if idh_price <> 0 or
                     idh_rma_type <> "I"
                  then
                     print_invoice = yes.
               end. /* FOR EACH idh_hist */

               if print_invoice = no then
                  next.
            end.  /* IF AVAIL rmc_ctrl */

            find ct_mstr where ct_code = ih_cr_terms no-lock no-error.

            if available ct_mstr then
               termsdesc = ct_desc.
            else
               termsdesc = "".
            find ad_mstr where ad_addr = ih_bill
               no-lock no-wait no-error.
            update billto = "".

            if available ad_mstr then do:
               {&SOIV1001-P-TAG10}
               assign
                  addr[1] = ad_name
                  addr[2] = ad_line1
                  addr[3] = ad_line2
                  addr[4] = ad_line3
                  addr[6] = ad_country.
               {mfcsz.i addr[5] ad_city ad_state ad_zip}.
               {&SOIV1001-P-TAG11}
               {gprun.i ""gpaddr.p"" }

               assign
                  billto[1] = addr[1]
                  billto[2] = addr[2]
                  billto[3] = addr[3]
                  billto[4] = addr[4]
                  billto[5] = addr[5]
                  billto[6] = addr[6].
               {&SOIV1001-P-TAG12}

               if addr[6] = "" and ih_po <> "" then
               assign
                  billto[6] = getTermLabel("PURCHASE_ORDER",5) + " " + ih_po
                  hdr_po = "".

               else
               assign
                  billto[6] = addr[6]
                  hdr_po = getTermLabel("PURCHASE_ORDER",14) + ": " + ih_po.
               {&SOIV1001-P-TAG13}

            end. /* IF AVAIL ad_mstr */

            find ad_mstr where ad_addr = ih_cust
               no-lock no-wait no-error.
            update soldto = "".

            if available ad_mstr then do:
               {&SOIV1001-P-TAG14}
               assign
                  addr[1] = ad_name
                  addr[2] = ad_line1
                  addr[3] = ad_line2
                  addr[4] = ad_line3
                  addr[6] = ad_country.
               {mfcsz.i addr[5] ad_city ad_state ad_zip}.
               {&SOIV1001-P-TAG15}
               {gprun.i ""gpaddr.p"" }
               assign
                  soldto[1] = addr[1]
                  soldto[2] = addr[2]
                  soldto[3] = addr[3]
                  soldto[4] = addr[4]
                  soldto[5] = addr[5]
                  soldto[6] = addr[6].

               /* GET SECOND CURRENCY FOR EURO DUAL CURRENCY PRINTING */
               /* CHANGED 2nd PARAMETER FROM ih_cust TO ih_bill */
               {etdcra.i ih_curr ih_bill}

               find cm_mstr where cm_addr = ih_cust no-lock no-error.
               if available cm_mstr then
                  resale = cm_resale.
               else
                  resale = "".
            end. /* IF AVAIL ad_mstr */

            /* GET VAT REG NO AND COUNTRY CODE FOR SHIP-TO */
            find ad_mstr where ad_addr = ih_ship
               no-lock no-wait no-error.

            if available ad_mstr then do:
               if ad_pst_id = "" then do:
                  find ad_mstr where ad_addr = ih_bill
                     no-lock no-wait no-error.

                  if available ad_mstr then do:
                     {gpvteprg.i}
                  end. /* IF AVAIL ad_mstr */

               end. /* IF ad_pst_id = "" */

               else do:
                  {gpvteprg.i}
               end. /* ELSE ad_pst_id <> "" */

            end. /* IF AVAIL ad_mstr */

            /* FOR RMAs, CHECK FOR CALL NUMBER */
            hdr_call = "".

            if rmaso then
               hdr_call = call-lbl + ih_ca_nbr.

            {&SOIV1001-P-TAG16}
            FORM /*GUI*/ 
               header
               getTermLabelRtColon("SALES_ORDER",15) format "x(15)" to 15
               ih_nbr
               getTermLabelRtColon("SHIP_DATE",20) format "x(20)"   to 55
               ih_ship_date
               getTermLabelRtColon("ORDER_DATE",15) format "x(15)" to 15
               ih_ord_date
               hdr_po            to 78 no-label
               getTermLabelRtColon("SALESPERSON(S)",15) format "x(15)" to 15
               ih_slspsn[1]
               ih_slspsn[2]
               getTermLabelRtColon("SHIP_TO",20) format "x(20)"     to 55
               ih_ship
               ih_slspsn[3]      at 17
               ih_slspsn[4]
               getTermLabelRtColon("SHIP_VIA",20) format "x(20)"    to 55
               ih_shipvia
               getTermLabelRtColon("CREDIT_TERMS",15) format "x(15)" to 15
               ih_cr_terms
               getTermLabelRtColon("BOL",10) format "x(10)"    to 55
               ih_bol
               " "               to 15
               termsdesc
               getTermLabelRtColon("FOB_POINT",15) format "x(15)"    to 55
               ih_fob
               getTermLabelRtColon("RESALE",15) format "x(15)" to 15
               resale
               hdr_call          to 64 no-label
               getTermLabelRtColon("REMARKS",15) format "x(15)" to 15
               ih_rmks           skip (1)
            with STREAM-IO /*GUI*/  frame phead2 width 90.

            FORM /*GUI*/  header
               fill ("-",77)format "x(77)" skip space (31)
               c-cont
               skip(8)
            with STREAM-IO /*GUI*/  frame continue page-bottom width 80.
            {&SOIV1001-P-TAG17}

            FORM /*GUI*/ 
               vcCreditCardMsg[1] skip
               vcCreditCardMsg[2] skip
               vcCreditCardMsg[3]
            with STREAM-IO /*GUI*/  frame soccmsg no-labels width 132 attr-space.

            /* **NOTE: THE CUSTOMER HAS PROMISED TO PAY USING A */
            /* CREDIT CARD */
            {pxmsg.i &MSGNUM=3867 &ERRORLEVEL=1 &MSGBUFFER=vcCreditCardMsg[1]}
            /* THE CARD USED AT ORDER TIME WILL BE PROCESSED FOR */
            /* PAYMENT */
            {pxmsg.i &MSGNUM=3868 &ERRORLEVEL=1 &MSGBUFFER=vcCreditCardMsg[2]}
            /* CUSTOMER IS RESPONSIBLE FOR PAYMENT IF CREDIT CARD */
            /* IS DENIED */
            {pxmsg.i &MSGNUM=3869 &ERRORLEVEL=1 &MSGBUFFER=vcCreditCardMsg[3]}

            /* PRINT LINE ITEMS */

            if first-of(ih_inv_nbr) then do:
               /* INITIALIZE VARIABLES FOR INVOICE TOTALS.*/
               {soivtot2.i}
               {&SOIV1001-P-TAG18}
               view frame continue.

               view frame phead2.
               {&SOIV1001-P-TAG19}

               if ih_fsm_type = "SC" then do:

                  svremarks = getTermLabel("FOR_PERIOD",25) + ": "
                     + string(ih_req_date,"99/99/99")
                     + " " + getTermLabel("TO",10) + ": "
                     + string(ih_due_date,"99/99/99").
                  put svremarks at 15.

                  svremarks = getTermLabel("SERVICE_CONTRACT",30) + ": "
                     + ih_sa_nbr.
                  put svremarks at 15.
               end. /* IF ih_fsm_type = "SC" */

               {&SOIV1001-P-TAG20}
               {gpcmtprt.i &type=in &id=ih_cmtindx &pos=3}
               put skip(1).
               {&SOIV1001-P-TAG21}
               /* IF THIS INVOICE IS FOR AN RMA WHICH REFERENCES */
               /* A CALL, PRINT HEADER COMMENTS FROM THAT CALL   */

               if rmaso then do:
                  /* NOTE: CA_CATEGORY = "0" FOR CALLS, AND  */
                  /*       "QUOTE" FOR CALL QUOTES.          */
                  find first ca_mstr
                     where ca_nbr = ih_ca_nbr
                     and ca_category = "0"
                     no-lock no-error.

                  if available ca_mstr then do:
                     put skip(1).
                     {gpcmtprt.i &type=in &id=ca_cmtindx &pos=3}
                  end.  /* IF AVAIL ca_mstr */
                  else do:
                     find first chm_mstr
                        where chm_nbr = ih_ca_nbr
                        and chm_category = "0"
                        no-lock no-error.

                     if available chm_mstr then do:
                        put skip(1).
                        {gpcmtprt.i &type=in &id=chm_cmtindx &pos=3}
                     end.  /* IF AVAIL chm_mstr */
                  end.  /* ELSE NOT AVAIL ca_mstr */
               end.  /* IF rmaso */

               if disc_det_key <> "1" then do:

                  run getTranslation(input disc_det_key,
                     output translation).

                  disc_prnt_label = translation.
               end.  /* IF  disc_det_key <> "1" */

               {gprun.i ""soivrp1a.p""
                        "(output invtot_container_amt,
                          output invtot_linecharge_amt)"}
               assign
                  invtot_line_total = invtot_line_total +
                                      invtot_container_amt +
                                      invtot_linecharge_amt
                  invtot_ord_amt = invtot_ord_amt +
                                   invtot_container_amt +
                                   invtot_linecharge_amt
                  ettot_line_total = ettot_line_total +
                                     invtot_container_amt +
                                     invtot_linecharge_amt
                  ettot_ord_amt = ettot_ord_amt +
                                  invtot_container_amt +
                                  invtot_linecharge_amt.
               {&SOIV1001-P-TAG22}
               hide frame phead2.

               hide frame continue.
               {&SOIV1001-P-TAG23}
            end.  /* IF FIRST-OF ih_inv_nbr */

            /*Check if this is a credit card order*/
            {gprunp.i "gpccpl" "p" "isCCOrder"
               "(input ih_nbr, output vlResult)"}
            /*If it is view credit card message frame*/
            if vlResult then
               display vcCreditCardMsg with frame soccmsg STREAM-IO /*GUI*/ .

            if disc_sum_key <> "1" and
               disc_sum_key <> disc_det_key
            then do:
               run getTranslation(input disc_sum_key,
                                  output translation).

               disc_prnt_label = translation.

            end. /* IF disc_sum_key <> "1" */

            /* PRINT DISCOUNT SUMMARY, DELETE DISC WKFL RECORDS */
            {sopiprn2.i}
            assign
               tot_prepaid_amt = tot_prepaid_amt + ih_hist.ih_prepaid
               tot_ptax_amt    = tot_ptax_amt    + ih_hist.ih_prep_tax.
            {&SOIV1001-P-TAG6}
            /* TRAILER */
            /* (Only display trailer after all SOs for this invoice */
            /* have been printed.)                                  */

            if not last-of(ih_inv_nbr) then do:
               {gprun.i ""soihtrl2.p""}

               /* ACCUMULATE TRAILER TOTALS USING SOIVTOT9.I      */
               /* ADDED TENTH I-O PARAMETER ETTOT_LINE_TOTAL,     */
               /* ELEVENTH    I-O PARAMETER ETTOT_DISC_AMT,       */
               /* TWELFTH     I-O PARAMETER ETTOT_TRL1_AMT,       */
               /* THIRTEENTH  I-O PARAMETER ETTOT_TRL2_AMT,       */
               /* FOURTEENTH  I-O PARAMETER ETTOT_TRL3_AMT,       */
               /* FIFTEENTH   I-O PARAMETER ETTOT_TAX_AMT AND     */
               /* SIXTEENTH   I-O PARAMETER ETTOT_ORD_AMT         */
               /* TO  ACCUMULATE TRAILER TOTALS FOR DUAL CURRENCY */
               run p-acc-totals (buffer ih_hist,
                  input-output invtot_nontaxable_amt,
                  input-output invtot_taxable_amt,
                  input-output invtot_line_total,
                  input-output invtot_disc_amt,
                  input-output invtot_trl1_amt,
                  input-output invtot_trl2_amt,
                  input-output invtot_trl3_amt,
                  input-output invtot_tax_amt,
                  input-output invtot_ord_amt,
                  input-output ettot_line_total,
                  input-output ettot_disc_amt,
                  input-output ettot_trl1_amt,
                  input-output ettot_trl2_amt,
                  input-output ettot_trl3_amt,
                  input-output ettot_tax_amt,
                  input-output ettot_ord_amt,
                  input-output invtot_container_amt,
                  input-output invtot_linecharge_amt) .

            end. /* IF NOT LAST-OF(IH_INV_NBR) */

            if last-of(ih_inv_nbr) then do:

               undo_txdetrp = true.

               {&SOIV1001-P-TAG36}
               {gprun.i  ""txdetrp.p"" "(input tax_tr_type,
                                         input ih_inv_nbr,
                                         input '*',
                                         input col-80,
                                         input 10)" }
               {&SOIV1001-P-TAG37}

               /* OBTAINING TOTAL INCLUDED TAX FOR THE TRANSACTION */
               {gprun.i ""txtotal1.p"" "(input '16',
                                         input  ih_inv_nbr,
                                         input  '*',
                                         input  0,
                                         output l_tax_in)"}

               {gprun.i ""soihtrl2.p""}
               /* OBTAINING TOTAL TAX AMOUNT FOR THE INVOICE */
               {gprun.i  ""txtotal.p"" "(input '16',
                                         input ih_inv_nbr,
                                         input '*',
                                         input 0,
                                         output tax_amt)" }

               /* ADJUSTING TOTAL TAX AMOUNT BY INCLUDED TAX */
               assign
                  tax_amt = tax_amt + l_tax_in
                  l_tax_in = 0
                  ord_amt = ord_amt + tax_amt.

               /* ACCUMULATE TRAILER TOTALS USING SOIVTOT9.I      */
               /* ADDED TENTH I-O PARAMETER ETTOT_LINE_TOTAL,     */
               /* ELEVENTH    I-O PARAMETER ETTOT_DISC_AMT,       */
               /* TWELFTH     I-O PARAMETER ETTOT_TRL1_AMT,       */
               /* THIRTEENTH  I-O PARAMETER ETTOT_TRL2_AMT,       */
               /* FOURTEENTH  I-O PARAMETER ETTOT_TRL3_AMT,       */
               /* FIFTEENTH   I-O PARAMETER ETTOT_TAX_AMT AND     */
               /* SIXTEENTH   I-O PARAMETER ETTOT_ORD_AMT         */
               /* TO  ACCUMULATE TRAILER TOTALS FOR DUAL CURRENCY */
               run p-acc-totals (buffer ih_hist,
                  input-output invtot_nontaxable_amt,
                  input-output invtot_taxable_amt,
                  input-output invtot_line_total,
                  input-output invtot_disc_amt,
                  input-output invtot_trl1_amt,
                  input-output invtot_trl2_amt,
                  input-output invtot_trl3_amt,
                  input-output invtot_tax_amt,
                  input-output invtot_ord_amt,
                  input-output ettot_line_total,
                  input-output ettot_disc_amt,
                  input-output ettot_trl1_amt,
                  input-output ettot_trl2_amt,
                  input-output ettot_trl3_amt,
                  input-output ettot_tax_amt,
                  input-output ettot_ord_amt,
                  input-output invtot_container_amt,
                  input-output invtot_linecharge_amt) .

               if can-find(mfc_ctrl where
                  mfc_module = "SO" and
                  mfc_seq = 170) then do:
                  {&SOIV1001-P-TAG24}
                  view frame continue.
                  {&SOIV1001-P-TAG25}
                  {soivtotb.i}
                  {&SOIV1001-P-TAG26}
                  hide frame continue.
                  {&SOIV1001-P-TAG27}
               end.  /* FOUND mfc_ctrl RECORD */

               add-trl-length = if tot_prepaid_amt <> 0 then
                                   3
                                else 0.

               {&SOIV1001-P-TAG28}
               if not et_dc_print then do:

                  if page-size - line-counter < 12 + add-trl-length then do:
                     {&SOIV1001-P-TAG29}
                     view frame continue.
                     page.
                     hide frame continue.
                     {&SOIV1001-P-TAG30}
                  end. /* IF page-size - line-counter < 12 */

                  do while page-size - line-counter > 12 + add-trl-length:
                     put skip(1).
                  end. /* DO WHILE page-size - line-counter > 12 */
               end.
               else do:

                  if page-size - line-counter < 15 + add-trl-length then
                  do:
                     {&SOIV1001-P-TAG31}
                     view frame continue.
                     page.
                     hide frame continue.
                     {&SOIV1001-P-TAG32}
                  end.

                  do while page-size - line-counter > 15 + add-trl-length:
                     put skip(1).
                  end.
               end.

               {&SOIV1001-P-TAG33}
               put msg skip.
               {&SOIV1001-P-TAG34}
               if not et_dc_print then
                  put fill("-",77) format "x(77)" skip.
               else put fill("-",99) format "x(99)" skip.
               currdisp = ih_curr.

               {etdcrc.i ih_curr ih_hist.ih}
               {soivto10.i}
               {&SOIV1001-P-TAG35}

               if tot_prepaid_amt <> 0 then
               do:
                  price_fmt = "-zzzz,zzz,zz9.99".
                  {gprun.i ""gpcurfmt.p"" "(input-output price_fmt,
                                     input rndmthd)"}

                  assign
                     tot_prepaid_amt:format in frame ihprepd = price_fmt
                     tot_ptax_amt:format in frame ihprepd = price_fmt
                     tot_prepaid_nett:format in frame ihprepd = price_fmt
                     amt_due_af_prep:format in frame ihprepd = price_fmt
                     tot_prepaid_nett = tot_prepaid_amt + tot_ptax_amt
                     amt_due_af_prep = invtot_ord_amt - tot_prepaid_nett.

                  if not et_dc_print then
                  display
                     tot_prepaid_amt
                     tot_ptax_amt
                     tot_prepaid_nett
                     amt_due_af_prep
                  with frame ihprepd STREAM-IO /*GUI*/ .
                  else do:
                     {gprunp.i "mcpl" "p" "mc-curr-conv"
                        "(input  ih_curr,
                          input  et_sec_curr,
                          input  et_rate1,
                          input  et_rate2,
                          input  tot_prepaid_amt,
                          input  true,        /* ROUND */
                          output et_tot_prepaid_amt,
                          output mc-error-number)"}
                     {gprunp.i "mcpl" "p" "mc-curr-conv"
                        "(input  ih_curr,
                          input  et_sec_curr,
                          input  et_rate1,
                          input  et_rate2,
                          input  tot_ptax_amt,
                          input  true,        /* ROUND */
                          output et_tot_ptax_amt,
                          output mc-error-number)"}
                     {gprunp.i "mcpl" "p" "mc-curr-conv"
                        "(input  ih_curr,
                          input  et_sec_curr,
                          input  et_rate1,
                          input  et_rate2,
                          input  tot_prepaid_nett,
                          input  true,        /* ROUND */
                          output et_tot_prepaid_nett,
                          output mc-error-number)"}
                     {gprunp.i "mcpl" "p" "mc-curr-conv"
                        "(input  ih_curr,
                          input  et_sec_curr,
                          input  et_rate1,
                          input  et_rate2,
                          input  amt_due_af_prep,
                          input  true,        /* ROUND */
                          output et_amt_due_af_prep,
                          output mc-error-number)"}

                     assign
                        tot_prepaid_amt:format
                        in frame ihprepdeuro = price_fmt
                        tot_ptax_amt:format
                        in frame ihprepdeuro = price_fmt
                        tot_prepaid_nett:format
                        in frame ihprepdeuro = price_fmt
                        amt_due_af_prep:format
                        in frame ihprepdeuro = price_fmt
                        et_tot_prepaid_amt:format
                        in frame ihprepdeuro = et_ord_amt:format
                        et_tot_ptax_amt:format
                        in frame ihprepdeuro = et_ord_amt:format
                        et_tot_prepaid_nett:format
                        in frame ihprepdeuro = et_ord_amt:format
                        et_amt_due_af_prep:format
                        in frame ihprepdeuro = et_ord_amt:format.
                     display
                        tot_prepaid_amt
                        tot_ptax_amt
                        tot_prepaid_nett
                        amt_due_af_prep
                        et_tot_prepaid_amt
                        et_tot_ptax_amt
                        et_tot_prepaid_nett
                        et_amt_due_af_prep
                     with frame ihprepdeuro STREAM-IO /*GUI*/ .
                  end.

               end. /* IF tot_prepaid_amt <> 0 */

            end. /* IF LAST-OF ih_inv_nbr */

         end.  /* DO FOR ih_hist */
      end.  /* FOR EACH ih_hist */
   end.  /* FOR EACH ih_buff */
end.  /* MAINLOOP */
SESSION:numeric-format = oldsession.

PROCEDURE p-get-ord-amt:
   /* THIS PROCEDURE IS DERIVED FROM SOIHTRL2.P AND  */
   /* OBTAINS THE TOTAL INVOICE VALUE                */

   define input  parameter p_inv_nbr as character no-undo.
   define output parameter l_ord_amt as decimal format
      "-zzzz,zzz,z99.99" no-undo.

   /* LOCAL VARIABLES */
   define variable l_ext_actual     like idh_price no-undo.
   define variable l_tmp_amt        as   decimal   no-undo.
   define variable mc-error-number  like msg_nbr   no-undo.
   /* l_ext_actual2 IS THE EXTENDED AMOUNT EXCLUDING DISCOUNT. IT WILL BE */
   /* USED FOR THE CALCULATION OF taxable_amt AND nontaxable_amt          */
   define variable l_ext_actual2    like idh_price no-undo.

   define buffer ih_hist for ih_hist.

   assign
      line_total  = 0
      taxable_amt = 0.

   for each ih_hist
      where ih_inv_nbr = p_inv_nbr
      no-lock
      break by ih_inv_nbr:

      assign
         line_total  = 0
         taxable_amt = 0.

      for each idh_hist
         fields (idh_inv_nbr idh_nbr      idh_price
                 {&SOIV1001-P-TAG39}
                 idh_qty_inv idh_rma_type idh_taxable)
         where idh_inv_nbr = ih_inv_nbr
         and   idh_nbr     = ih_nbr
         no-lock:

         assign
            l_ext_actual  =  idh_price * idh_qty_inv
            l_ext_actual2 = (idh_price * idh_qty_inv
                             * (1 - ih_disc_pct / 100)).


         /* ROUND PER DOCUMENT CURRENCY ROUND METHOD */

         {gprunp.i "mcpl" "p" "mc-curr-rnd"
            "(input-output l_ext_actual,
              input        rndmthd,
                 output       mc-error-number)" }
         if mc-error-number <> 0
         then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
         end.

         {gprunp.i "mcpl" "p" "mc-curr-rnd"
            "(input-output l_ext_actual2,
              input        rndmthd,
              output       mc-error-number)" }
         if mc-error-number <> 0
         then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
         end. /* IF mc-error-number <> 0 */

         /* CHECK AUTHORIZATION RECORDS FOR DIFFERENT EXT PRICE */
         if idh_sched
         then do:

            auth_found = no.

            {gprun.i ""soauthbl.p""
                "(input idh_inv_nbr,
                  input idh__qadc06,
                  input idh_nbr,
                  input idh_line,
                  input idh_part,
                  input idh_price,
                  input idh_site,
                  input l_ext_actual,
                  output auth_price,
                  output auth_found)"}

            l_ext_actual = auth_price.

         end. /*IF idh_sched */

         line_total = line_total + l_ext_actual.

         if idh_taxable
         then
            taxable_amt = taxable_amt + l_ext_actual2.

      end. /* FOR EACH idh_hist */

      disc_amt = (- line_total * (ih_disc_pct / 100)).

      /* ROUND PER DOCUMENT CURRENCY ROUND METHOD */
      {gprunp.i "mcpl" "p" "mc-curr-rnd"
         "(input-output disc_amt,
           input        rndmthd,
           output       mc-error-number)" }

      if mc-error-number <> 0
      then do:
         {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
      end.

      /* ALL PROCEDURES USED FOR CALCULATING VARIOUS TOTALS         */
      /* PERTAINING TO THE INVOICE ARE CLUBBED TOGETHER AND WOULD BE*/
      /* RUN ONLY ONCE WITHIN THE ih_hist loop, SO THAT THEY GET    */
      /* ADDED CORRECTLY TO l_ord_amt                               */

      if last-of(ih_inv_nbr)
      then do:

         /* OBTAIN INVOICE TOTAL TAX */
         {gprun.i ""txtotal.p""
            "(input  '16',
              input  ih_inv_nbr,
              input  '*',
              input  0,      /* ALL LINES */
              output tax_amt)"}

         /* OBTAINING TOTAL INCLUDED TAX FOR THE TRANSACTION */
         {gprun.i ""txtotal1.p""
            "(input '16',
              input  ih_inv_nbr,
              input  '*',
              input  0,
              output l_tax_in)"}

      end. /* IF LAST-OF(ih_inv_nbr) */

      /* JUST MOVED CODE FROM ABOVE AS THIS CALCULATION SHOULD BE */
      /* SALES ORDER WISE(ih_nbr) AND THEREFORE SHOULD BE RUN FOR */
      /* ALL ih_hist RECORDS                                      */
      {gprun.i ""txabsrb.p""
         "(input ih_inv_nbr,
           input ih_nbr,
           input '16',
           input-output line_total,
           input-output taxable_amt)"}

      /* ADJUSTING LINE TOTALS AND TAXABLE AMOUNT BY INCLUDED TAX */
      assign
         line_total       = line_total - l_tax_in
         tax_amt          = tax_amt + l_tax_in
         l_tax_in         = 0
         l_ord_amt        = l_ord_amt  + line_total + disc_amt + ih_trl1_amt
                            + ih_trl2_amt + ih_trl3_amt + tax_amt.

   end. /* FOR EACH ih_hist */

end. /* PROCEDURE p-get-ord-amt */

PROCEDURE p-acc-totals:
   /* THIS PROCEDURE ACCUMULATES TRAILER TOTALS FOR GTM */

   define parameter buffer ih_hist       for  ih_hist.

   define input-output parameter invtot_nontaxable_amt
      as decimal no-undo.
   define input-output parameter invtot_taxable_amt
      as decimal no-undo.
   define input-output parameter invtot_line_total
      as decimal no-undo.
   define input-output parameter invtot_disc_amt as decimal no-undo.
   define input-output parameter invtot_trl1_amt
      like ih_trl1_amt no-undo.
   define input-output parameter invtot_trl2_amt
      like ih_trl2_amt no-undo.
   define input-output parameter invtot_trl3_amt
      like ih_trl3_amt no-undo.
   define input-output parameter invtot_tax_amt as decimal no-undo.
   define input-output parameter invtot_ord_amt as decimal no-undo.

   define input-output parameter ettot_line_total as decimal no-undo.
   define input-output parameter ettot_disc_amt   as decimal no-undo.
   define input-output parameter ettot_trl1_amt
      like ih_trl1_amt no-undo.
   define input-output parameter ettot_trl2_amt
      like ih_trl2_amt no-undo.
   define input-output parameter ettot_trl3_amt
      like ih_trl3_amt no-undo.
   define input-output parameter ettot_tax_amt    as decimal no-undo.
   define input-output parameter ettot_ord_amt    as decimal no-undo.
   define input-output parameter invtot_container_amt as decimal no-undo.
   define input-output parameter invtot_linecharge_amt as decimal no-undo.

   define variable tmpamt as decimal no-undo.
   define variable mc-error-number like msg_nbr no-undo.

   {soivtot9.i}
end. /* PROCEDURE P-ACC-TOTALS */

PROCEDURE getTranslation:
/*---------------------------------------------------------------------------
Purpose: Get translation from language detail
Parameters: pKey1 - lngd_key1
pTranslation - output lngd_translation

Notes: Added by ECO N06R to prevent action segment compile error.
---------------------------------------------------------------------------*/.
   define input parameter pKey1 as character no-undo.
   define output parameter pTranslation as character no-undo.

   for first lngd_det fields(lngd_translation) where
         lngd_dataset begins "soprint" and
         lngd_field = "det_disc_prnt" and
         lngd_lang = global_user_lang and
         lngd_key1 = pKey1:
   end.

   if available lngd_det then pTranslation = lngd_translation.

END PROCEDURE. /*GetTranslation*/
